package com.agriculture.mapper;

import com.agriculture.domain.Order;
import com.agriculture.domain.OrderStatusHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;

import java.util.List;


@Mapper
public interface OrderMapper {
    Order findById(Long orderId);
    
    int updateOrderStatus(
        @Param("orderId") Long orderId,
        @Param("status") String status,
        @Param("operator") String operator,
        @Param("notes") String notes
    );
    
    int insertOrderHistory(OrderStatusHistory history);

    List<Order> getBuyOrders(
        @Param("role") String role,
        @Param("status") String status,
        @Param("search") String search,
        @Param("buyerId") Long buyerId,
        @Param("sellerId") Long sellerId,
        @Param("offset") int offset,
        @Param("pageSize") int pageSize
    );

    int countBuyOrders(
        @Param("role") String role,
        @Param("status") String status,
        @Param("search") String search,
        @Param("buyerId") Long buyerId,
        @Param("sellerId") Long sellerId
    );

    int insert(Order order);

    Order selectById(Long id);

    int updateById(Order order);

    List<Order> selectBuyOrders(
        @Param("role") String role,
        @Param("status") String status,
        @Param("keyword") String keyword,
        @Param("buyerId") Long buyerId,
        @Param("sellerId") Long sellerId,
        @Param("offset") int offset,
        @Param("limit") int limit
    );

    List<Order> selectCompletedBuyOrders(
        @Param("role") String role,
        @Param("status") String status,
        @Param("search") String search,
        @Param("buyerId") Long buyerId,
        @Param("sellerId") Long sellerId,
        @Param("offset") int offset,
        @Param("limit") int pageSize
    );

    int countCompletedBuyOrders(
        @Param("role") String role,
        @Param("status") String status,
        @Param("search") String search,
        @Param("buyerId") Long buyerId,
        @Param("sellerId") Long sellerId
    );

    List<Order> selectOrdersByBuyer(@Param("buyerId") Long buyerId, 
                                   @Param("orderType") String orderType);

    List<Order> selectOrdersBySeller(@Param("sellerId") Long sellerId, 
                                    @Param("orderType") String orderType);

    List<Order> getSellOrders(
        @Param("role") String role,
        @Param("status") String status, 
        @Param("search") String search,
        @Param("sellerId") Long sellerId,
        @Param("buyerId") Long buyerId,
        @Param("offset") int offset,
        @Param("pageSize") int pageSize
    );

    int countSellOrders(
        @Param("role") String role,
        @Param("status") String status,
        @Param("search") String search, 
        @Param("sellerId") Long sellerId,
        @Param("buyerId") Long buyerId
    );

    int updateOrderShipment(@Param("order") Order order);
} 